package org.x.legalcasemod.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.x.commonmod.config.Result;
import org.x.commonmod.util.AliyunOSSOperator;

@Slf4j
@RestController
public class UploadController {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;
    @PostMapping("/upload")
    public Result handleFileUpload(MultipartFile file) throws Exception {
        //使用阿里云OSS上传文件
        log.info("文件上传：{}",file.getOriginalFilename());
        //将文件上传到阿里云OSS
        String url = aliyunOSSOperator.upload(file.getBytes(), file.getOriginalFilename());
        return Result.ok(url);
    }
}
